﻿<%@ Page Title="usercategory" Language="C#" MasterPageFile="~/EasyUI.master" AutoEventWireup="true" CodeBehind="List.aspx.cs" Inherits="jnagr.Web.usercategory.List" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
     <script type="text/javascript">
         $(function () {
             InitGird();
             InitSearch();
         });
         //初始化表格
         function InitGird() {
             $('#tt').datagrid({
                 title: '人员类别列表', //表格标题
                 url: 'GetUsercate.ashx', //请求数据的页面
                 sortName: 'uname', //排序字段
                 idField: 'uid', //标识字段,主键
                 iconCls: '', //标题左边的图标
                 width: '100%', //宽度
                 //height: $(parent.document).find("#mainPanle").height() - 35 > 0 ? $(parent.document).find("#mainPanle").height() - 35 : 500, //高度
                 nowrap: false, //是否换行，True 就会把数据显示在一行里
                 striped: true, //True 奇偶行使用不同背景色
                 collapsible: false, //可折叠
                 sortOrder: 'desc', //排序类型
                 remoteSort: true, //定义是否从服务器给数据排序
                 fitColumns: true,
                 method: 'post',
                 columns: [[
                     { field: 'ckb', checkbox: true },
                     { title: '用户名', field: 'uname', width: 80, sortable: true },
                    { title: '姓名', field: 'utruename', width: 60 },
                    { title: '手机', field: 'uphone', width: 60 },
                    { title: '邮箱', field: 'uemail', width: 120 },
                    { title: '单位', field: 'uunit', width: 100 },
                    { title: '地址', field: 'madd', width: 150, sortable: true },
                    { title: '单位电话', field: 'utel', width: 100 },
                    { title: '类别', field: 'caname', width: 200 }
                 ]],
                 toolbar: "#tab_toolbar",
                 queryParams: { "action": "query" },
                 pagination: true, //是否开启分页
                 pageNumber: 1, //默认索引页
                 pageSize: 20, //默认一页数据条数
                 rownumbers: true //行号
             });
         }
         //初始化搜索框
         function InitSearch() {
             $("#ipt_search").searchbox({
                 width: 200,                 
                 searcher: function (val, name) {
                     $('#tt').datagrid('options').queryParams.search_type = name;
                     $('#tt').datagrid('options').queryParams.search_value = val;
                     $('#tt').datagrid('reload');
                 },
                 prompt: '请输入查询信息'
             });
             $('#cc').combobox({
                 url: '../categroy/GetCate.ashx?action=ddllist',
                 valueField: 'caid',
                 textField: 'caname',
                 panelHeight: 'auto',
                 editable: false,
                 onLoadSuccess: function () {
                     var data = $('#cc').combobox('getData');
                     if (data.length > 0)
                     $("#cc").combobox('select',data[0].caid);
                 }
             });
         }
         function getids(rows) {
             var ids = "";
             for (var i = 0; i < rows.length; i++)
                 ids = ids + rows[i].uid + ",";
             if (ids != "")
                 ids = ids.substr(0, ids.length - 1);
             return ids;

         }
         function getQueryParams(queryParams) {
             var caid = $('#cc').combobox('getValue');
             queryParams.caid = caid;             
             return queryParams;

         }
         //增加查询参数，重新加载表格  
         function reloadgrid() {

             //查询参数直接添加在queryParams中      
             var queryParams = $('#tt').datagrid('options').queryParams;
             getQueryParams(queryParams);
             $('#tt').datagrid('options').queryParams = queryParams;
             $("#tt").datagrid('reload');

         }
         function getUser() {
             reloadgrid();
         }
         function getallUser() {
             var queryParams = $('#tt').datagrid('options').queryParams;
             queryParams.caid = "";
             $('#tt').datagrid('options').queryParams = queryParams;
             $("#tt").datagrid('reload');
         }
         
         function setUser() {             
             var rows = $('#tt').datagrid('getSelections');
             if (rows == null) {
                 $.messager.alert("提示", "请选择要设置的行！", "info");
             }
             if (rows) {
                 $.messager.confirm('提示', '你确定要设置吗？', function (r) {
                     if (r) {
                         var uids = getids(rows);
                         var caid = $('#cc').combobox('getValue');
                         $('#fm').form('submit', {
                             url: 'GetUsercate.ashx?uids=' + uids + '&caid='+caid+'&action=add',
                             onSubmit: function () {
                                 //return $(this).form('validate');  
                             },
                             success: function (result) {
                                 if (result.indexOf("T") == 0) {
                                     $('#dlg').dialog('close');
                                     $('#tt').datagrid('clearSelections'); //清空选中的行  
                                     $.messager.alert("提示", "恭喜您，信息设置成功！", "info");                                      
                                     $('#tt').datagrid('reload');                                   

                                 }
                                 else if ((result.indexOf("F") == 0)) {
                                     $.messager.alert("提示", "添加失败，请重新操作！", "info");
                                     return;
                                 }
                                 else if ((result.indexOf("L") == 0)) {
                                     $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                                     top.location = '/index.aspx';
                                     return;
                                 }
                             }
                         });
                     }
                 })
             }
         }

         function removeUser() {
             var rows = $('#tt').datagrid('getSelections');
             if (rows == null) {
                 $.messager.alert("提示", "请选择要设置的行！", "info");
             }
             if (rows) {
                 $.messager.confirm('提示', '你确定要删除分组设置吗？', function (r) {
                     if (r) {
                         var uids = getids(rows);
                         var caid = $('#cc').combobox('getValue');
                         $('#fm').form('submit', {
                             url: 'GetUsercate.ashx?uids=' + uids + '&caid=' + caid + '&action=delete',
                             onSubmit: function () {
                                 //return $(this).form('validate');  
                             },
                             success: function (result) {
                                 if (result.indexOf("T") == 0) {
                                     $('#dlg').dialog('close');
                                     $('#tt').datagrid('clearSelections'); //清空选中的行  
                                     $.messager.alert("提示", "恭喜您，信息删除成功！", "info");
                                     $('#tt').datagrid('reload');

                                 }
                                 else if ((result.indexOf("F") == 0)) {
                                     $.messager.alert("提示", "添加失败，请重新操作！", "info");
                                     return;
                                 }
                                 else if ((result.indexOf("L") == 0)) {
                                     $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                                     top.location = '/index.aspx';
                                     return;
                                 }
                             }
                         });
                     }
                 })
             }
         }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table id="tt">
    </table>
    <div id="tab_toolbar" style="padding: 4px;">
        <table cellpadding="0" cellspacing="0" style="width: 100%">
            <tr>

                <td style="padding-left: 2px">
                    <input id="cc" class="easyui-combobox" name="cc" style="width:200px;" />                   
                    <a href="#" onclick="setUser();" id="a_add"
                        class="easyui-linkbutton" iconcls="icon-ok">设置分组</a>  
                    <a href="#" onclick="removeUser();return false;" id="a_del" class="easyui-linkbutton" iconcls="icon-cancel">删除分组</a>  
                    <a href="#" onclick="getUser();return false;" id="a1" class="easyui-linkbutton" iconcls="icon-search">搜索分组</a>  
                    <a href="#" onclick="getallUser();return false;" id="a2" class="easyui-linkbutton" iconcls="icon-search">所有分组</a>              
                </td>
                <td style="text-align: right; padding-right: 15px">
                    <input id="ipt_search" menu="#search_menu" />
                    <div id="search_menu" style="width: 120px">
                        <div name="usernum">
                            用户名
                        </div>
                        <div name="username">
                            姓 名
                        </div>
                    </div>
                </td>
            </tr>
        </table>
    </div> 
     <div id="dlg" class="easyui-dialog" style="width: 400px; height: auto; padding: 10px 20px"
            data-options="closed:true,buttons:'#dlg-buttons',shadow:false">

            <form id="fm" method="post">
                
            </form>
        </div>
        <div id="dlg-buttons">
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveUser()">保存</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
        </div>
</asp:Content>
